package com.wc.alorithm_blue_bridge_history.simulation_match3.C;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/8 15:03
 * @description
 * 只能被1和本身整除的数称为质数。
 * 请问在1 (含）到1000000(含）中，有多少个质数的各个数位上的数字之和为23。
 * https://www.lanqiao.cn/problems/16573/learning/?problem_list_id=29&page=1
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1000010;
    static int[] primes = new int[N];
    static boolean[] isNotPrime = new boolean[N];
    static int idx = 0;

    static void ola() {
        isNotPrime[0] = isNotPrime[1] = true;
        for (int i = 2; i < N; i++) {
            if (!isNotPrime[i]) primes[++idx] = i;
            for (int j = 1; primes[j] * i < N; j++) {
                isNotPrime[primes[j] * i] = true;
                if (primes[j] % i == 0) break;
            }
        }
    }

    public static void main(String[] args) {
        ola();
        int res = 0;
        for (int i = 1; i <= idx; i++) {
            if (is23(primes[i])) {
                res++;
            }
        }
//        for (int i = 1; i <= 1000000; i++) {
//            if (is23(i) && isPrime(i)) {
//                res++;
//            }
//        }
        out.println(res);
        out.flush();
    }

    static boolean is23(int x) {
        int sum = 0;
        while (x > 0) {
            sum += x % 10;
            x /= 10;
        }
        return sum == 23;
    }

    static boolean isPrime(int x) {
        if (x <= 1) return false;
        for (int i = 2; i * i <= x; i++) {
            if (x % i == 0) return false;
        }
        return true;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}